package com.newbee.progressdlg;

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.view.Gravity;
import android.widget.ImageView;
import android.widget.TextView;

import com.hhu.newbee.R;

public class PlayProgressDlg extends Dialog
{
	private Context context = null;
	private static PlayProgressDlg customProgressDialog = null;

	public PlayProgressDlg(Context context)
	{
		super(context);
		this.context = context;
	}

	public PlayProgressDlg(Context context, int theme)
	{
		super(context, theme);
	}

	public static PlayProgressDlg createDialog(Context context)
	{
		customProgressDialog = new PlayProgressDlg(context,
				R.style.CustomProgressDialog);
		customProgressDialog.setContentView(R.layout.progress_dialog);
		customProgressDialog.getWindow().getAttributes().gravity = Gravity.CENTER;

		return customProgressDialog;
	}

	public void onWindowFocusChanged(boolean hasFocus)
	{

		if (customProgressDialog == null)
		{
			return;
		}

		ImageView imageView = (ImageView) customProgressDialog
				.findViewById(R.id.loadingImageView);
		AnimationDrawable animationDrawable = (AnimationDrawable) imageView
				.getBackground();
		animationDrawable.start();
	}

	/**
	 * 
	 * [Summary] setTitile 标题
	 * 
	 * @param strTitle
	 * @return
	 * 
	 */
	public PlayProgressDlg setTitile(String strTitle)
	{
		return customProgressDialog;
	}

	/**
	 * 
	 * [Summary] setMessage 提示内容
	 * 
	 * @param strMessage
	 * @return
	 * 
	 */
	public PlayProgressDlg setMessage(String strMessage)
	{
		TextView tvMsg = (TextView) customProgressDialog
				.findViewById(R.id.id_tv_loadingmsg);

		if (tvMsg != null)
		{
			tvMsg.setText(strMessage);
		}

		return customProgressDialog;
	}
}